<template>
  <div class='container'>
  <Modal
  :title="showTitle"
  :value="showAdd"
  @on-cancel='cancel'
  @on-ok="ok"
  width="300px"
  >
  <span class="san">学科名称</span>
  <Input placeholder="请输入学科名称" v-model="value" style="margin-bottom:10px;width:150px"></Input>
  <div>
    <span style="margin:15px">是否显示</span>
    <el-switch v-model="isOpan"></el-switch>
  </div>
  </Modal>
  </div>
</template>
<script>
import { update, add } from '@/api/hmmm/subjects'
export default {
  props: {
    showAdd: {
      type: Boolean,
      default: false
    }
  },
  computed: {
    showTitle () {
      return this.isID ? '修改学科' : '添加学科'
    }
  },
  data () {
    return {
      value: '',
      row: {},
      isOpan: '',
      isID: false
    }
  },
  methods: {
    cancel () {
      this.$emit('update:showAdd', false)
    },
    async ok () {
      if (this.isID) {
        this.row.subjectName = this.value
        await update(this.row)
        this.$message.success('修改成功')
      } else {
        await add({ subjectName: this.value, isFrontDisplay: this.isOpan })
        this.$message.success('添加成功')
      }
      this.value = ''
      this.isOpan = false
      this.$emit('update:showAdd', false)
      this.$emit('getList')
    },
    getRow (row) {
      this.isID = true
      this.row = row.data
      this.value = this.row.subjectName
      this.isOpan = this.row.isFrontDisplay === 0
    }
  }
}
</script>

<style scoped lang='less'>

</style>
